package com.xt.stock.project.controlle.data;

import com.xt.stock.project.common.basic.GlobalResult;
import com.xt.stock.project.common.constant.XtCodeConstant;
import com.xt.stock.project.common.exception.XtServiceException;
import com.xt.stock.project.service.data.TushareService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tuShare")
public class TushareController {

    @Autowired
    private TushareService tushareService;

    @ApiOperation(value = "/getStockData", notes="获取股票列表")
    @RequestMapping(value = "/getStockData", method = RequestMethod.POST)
    public GlobalResult getStockData() {
        GlobalResult result = new GlobalResult();

        try {
            tushareService.getStockData();
        } catch (XtServiceException e) {
            return GlobalResult.fail(e.getErrorCode(),e.getMessage());
        }

        return result;
    }

    @ApiOperation(value = "/getDailyData", notes="获取每日数据")
    @RequestMapping(value = "/getDailyData", method = RequestMethod.POST)
    public void getDailyData() {
        tushareService.getDailyData();
    }

}
